package com.mini.cn.goods.io.netty.ws.info;


import io.netty.buffer.ByteBuf;
import io.netty.buffer.PooledByteBufAllocator;
import io.netty.buffer.Unpooled;


/**
 * Created with IntelliJ IDEA.

 * User: fly
 * Date: 2020-05-27
 * Time: 10:11 上午
 */
public class LCDataPacket {
    public byte[] content;//推送

    public static ByteBuf coverToBytes(LCDataPacket lcDataPacket) {
        byte[] content = lcDataPacket.content;
        ByteBuf byteBuf = Unpooled.directBuffer(content.length);
        byteBuf.writeBytes(content);
        return byteBuf;
    }

    public static ByteBuf coverToBytesNoPool(byte[] content) {
        ByteBuf byteBuf = Unpooled.directBuffer(content.length);
        byteBuf.writeBytes(content);
        return byteBuf;
    }


    public static ByteBuf coverFastMsgNoAckToBytes(byte[] content) {
        //pool 池化内存释放必须在同一个线程中
        //fast 因为申请和释放都是业务线程中自己控制所以可以改为池化内存
        ByteBuf byteBuf = PooledByteBufAllocator.DEFAULT.buffer(content.length);
        byteBuf.writeBytes(content);
        return byteBuf;
    }
}
